package com.cgtong.android.widget;

import android.os.CountDownTimer;
import android.widget.Button;

/**
 * Created by Sky.Bing on 2017/10/23.
 */

public class ValidCodeTime extends CountDownTimer {
    private Button mTimeSetBtn;

    public ValidCodeTime(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
    }

    public void setTimeSetBtn(Button button) {
        this.mTimeSetBtn = button;
    }

    @Override
    public void onFinish() {// 计时完毕时触发
        if (null != mTimeSetBtn) {
            mTimeSetBtn.setText("获取验证码");
            mTimeSetBtn.setClickable(true);
        }
    }

    @Override
    public void onTick(long millisUntilFinished) {// 计时过程显示
        if (null != mTimeSetBtn) {
            mTimeSetBtn.setClickable(false);
            mTimeSetBtn.setText(millisUntilFinished / 1000 + "秒");
        }
    }
}